//
//  EnergyPriceView.m
//  Ginix
//
//  Created by 冯志强 on 2025/3/5.
//

#import "EnergyPriceView.h"

@interface EnergyPriceView()
@property (nonatomic,strong) UIImageView * bgView;
@property (nonatomic,strong) YYLabel * numLabel;
@end

@implementation EnergyPriceView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setSubViewLayout];
    }
    return self;
}

-(void)setSubViewLayout{
    
    [self addSubview:self.bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@0);
    }];
    
    [self addSubview:self.numLabel];
    [_numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(@0).offset(2 * FMScaleX);
        make.left.mas_offset(65 * FMScaleX);
    }];
}

-(void)setInfoModel:(EnergyInfoModel *)infoModel{
    
    if (UserInfoModel.shareInstance.userModel.isBind == 1) {
        NSMutableAttributedString * attstr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@" %.2f",infoModel.balanceRecord.coinNumber]];

        NSMutableAttributedString * obj = [NSMutableAttributedString yy_attachmentStringWithContent:({
            UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 3 * FMScaleX, 26 * FMScaleX, 26 * FMScaleX)];
            imageView.image = [UIImage imageNamed:@"Energy_price_icon"];
            imageView;
              }) contentMode:UIViewContentModeRight attachmentSize:CGSizeMake(26 * FMScaleX, 26 * FMScaleX) alignToFont:Regular(16) alignment:YYTextVerticalAlignmentCenter];
        [attstr insertAttributedString:obj atIndex:0];
        self.numLabel.attributedText = attstr;
        self.numLabel.font = Medium(14);
        self.numLabel.textColor = RDRGB(0x714933);
    }
}

-(UIImageView *)bgView{
    
    if (!_bgView) {
        _bgView = [[UIImageView alloc]init];
        _bgView.image = [UIImage imageNamed:@"Energy_price_bg"];
    }
    return _bgView;
}
-(YYLabel *)numLabel{
    
    if (!_numLabel) {
        _numLabel = [[YYLabel alloc]init];
        _numLabel.font = Medium(14);
        _numLabel.textColor = RDRGB(0x714933);
        _numLabel.text = @"   ---";

    }
    return _numLabel;
}
@end
